using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Devices.Sensors;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace DoodleJump3
{  
    abstract class Screen
    {
        //Touch Input
        protected TouchCollection touchCollection;
        
        //Accelerometer Input
        protected Accelerometer accel;
        protected Vector3 accelReading;
        protected bool accelActive;

        //Graphics / Content
        protected GraphicsDeviceManager graphics;
        protected SpriteBatch spriteBatch;
        protected ContentManager contentManager;

        //Buttons for navigation
        protected List<Button> buttons;

        public Screen(GraphicsDeviceManager graphics, ContentManager contentManager, SpriteBatch spriteBatch)
        {
            this.graphics = graphics;
            this.spriteBatch = spriteBatch;
            this.contentManager = contentManager;

            accelReading = new Vector3();
            accelActive = false;

            accel = new Accelerometer();
            try
            {
                accel.Start();
                accelActive = true;
            }
            catch (AccelerometerFailedException e)
            {
                // The accelerometer could not be started
                accelActive = false;
            }
            catch (UnauthorizedAccessException e)
            {
                // This exception is thrown in the emulator-which doesn't support an accelerometer.
                accelActive = false;
            }

            buttons = new List<Button>();
        }

        protected void updateAccelerometer()
        {
            accel.ReadingChanged +=
                new EventHandler<AccelerometerReadingEventArgs>(AccelerometerReadingChanged);
        }

        private void AccelerometerReadingChanged(object sender, AccelerometerReadingEventArgs e)
        {
            accelReading.X = (float)e.X;
            accelReading.Y = (float)e.Y;
            accelReading.Z = (float)e.Z;
        }

        protected virtual void updateTouch()
        {
            touchCollection = TouchPanel.GetState();
            foreach (TouchLocation tl in touchCollection)
            {
                if ((tl.State == TouchLocationState.Pressed)
                        || (tl.State == TouchLocationState.Moved))
                {
                    
                }
            }
        }

        public abstract void Update(GameTime gameTime);

        public abstract void Draw();

        public List<Button> getButtons()
        {
            return buttons;
        }
    }
}
